package com.hundsun.yr.universal.p2p.ui.activity;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.view.ViewPager;
import android.view.View;

import com.hundsun.mobile.zwgt.R;
import com.hundsun.yr.universal.library.eventbus.EventCenter;
import com.hundsun.yr.universal.library.netstatus.NetUtils.NetType;
import com.hundsun.yr.universal.library.widget.HSSegmentControl.OnSegmentControlClickListener;
import com.hundsun.yr.universal.library.widget.NoScrollViewPager;
import com.hundsun.yr.universal.p2p.interactor.impl.RechangeSegmentInteractorImpl;
import com.hundsun.yr.universal.p2p.presenter.base.Presenter;
import com.hundsun.yr.universal.p2p.presenter.impl.BaseSegmentPresenterImpl;
import com.hundsun.yr.universal.p2p.ui.activity.base.BaseActivity;
import com.hundsun.yr.universal.p2p.ui.activity.base.BaseFragment;
import com.hundsun.yr.universal.p2p.ui.adapter.SegmentBasePagerAdapter;
import com.hundsun.yr.universal.p2p.view.base.BaseSegmentView;
import com.umeng.analytics.MobclickAgent;

import java.util.ArrayList;
import java.util.List;


/**
 * @version V1.0
 * @Title: MineInvestActivity.java
 * @Description: 充值
 * @date 2015-12-9 下午2:35:36
 * @author:hejun.shen
 * @email:shenhj15971@hundsun.com
 * @replace author:
 * @replace date:
 */
public class RechangeNewActivity extends BaseActivity implements BaseSegmentView,
        OnSegmentControlClickListener {
    /**
     * 分段选择器
     **/
//    private HSSegmentControl segment_control = null;
    private Presenter mPresenter = null;
    private NoScrollViewPager noScrollViewPager = null;
    private TabLayout tabLayout = null;
    /**
     * fragment适配器
     **/
    private SegmentBasePagerAdapter adapter = null;
    private ArrayList<String> list_title;
    public boolean MINERECHARGE = false;


    @Override
    protected boolean isApplyKitKatTranslucency() {
        // TODO Auto-generated method stub
        return true;
    }

    @Override
    protected void getBundleExtras(Bundle extras) {
        // TODO Auto-generated method stub
        MINERECHARGE = extras.getBoolean("MINERECHARGE",true);
    }

    @Override
    protected int getContentViewLayoutID() {
        // TODO Auto-generated method stub
        return R.layout.act_rechange_new;
    }

    @Override
    protected void onEveComming(@SuppressWarnings("rawtypes") EventCenter eventCenter) {
        // TODO Auto-generated method stub
/*        switch (eventCenter.getEventCode()) {
            case Extras.RECHANGE_SUCCESS:// TODO: 2017/6/19 没用
                finish();
                break;

            default:
                break;
        }*/
    }

    @Override
    protected boolean isBindEventBusHere() {
        // TODO Auto-generated method stub
        return true;
    }

    @Override
    protected View getLoadingTargetView() {
        // TODO Auto-generated method stub
        return null;
    }

    @Override
    protected void initViewsAndEvents() {
        // TODO Auto-generated method stub

        setToolbarTitle(R.string.recharge_title);

        noScrollViewPager = findView(R.id.viewpager);
        noScrollViewPager.setNoScroll(false);


        /**标题栏底部横线**/
//        findView(R.id.line_bottom).setVisibility(View.GONE);
        /**tablayout初始化**/
        tabLayout = findView(R.id.tab_layout);

        //list_title初始化
        list_title = new ArrayList<>();
        list_title.add("银行转账");
       // list_title.add("支付宝转账");
        list_title.add("快捷充值");
        mPresenter = new BaseSegmentPresenterImpl(this, this, new RechangeSegmentInteractorImpl());
        mPresenter.initialized();
    }

    @Override
    protected void initImmersionBar() {
        super.initImmersionBar();
        mImmersionBar.titleBar(R.id.common_toolbar).init();
    }

    @Override
    protected void onNetworkConnected(NetType type) {
        // TODO Auto-generated method stub

    }

    @Override
    protected void onNetworkDisConnected() {
        // TODO Auto-generated method stub

    }

    @Override
    protected boolean isApplyStatusBarTranslucency() {
        // TODO Auto-generated method stub
        return true;
    }

    @Override
    protected boolean toggleOverridePendingTransition() {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    protected TransitionMode getOverridePendingTransitionMode() {
        // TODO Auto-generated method stub
        return null;
    }

    /**
     * 绑定适配器
     *
     * @param viewPager
     * @param fragments
     */
    private void setupViewPager(ViewPager viewPager, List<BaseFragment> fragments) {
        tabLayout.setTabMode(TabLayout.MODE_FIXED);
        adapter = new SegmentBasePagerAdapter(getSupportFragmentManager(), fragments);
        viewPager.setAdapter(adapter);
        adapter.notifyDataSetChanged();
        //viewpager和tablayout绑定
        tabLayout.setupWithViewPager(viewPager);
        tabLayout.getTabAt(0).setText(list_title.get(0));
        //tabLayout.getTabAt(1).setText(list_title.get(1));
        tabLayout.getTabAt(1).setText(list_title.get(1));
        noScrollViewPager.setCurrentItem(1,false);

    }


    @Override
    public void initializeViews(List<BaseFragment> fragments) {
        // TODO Auto-generated method stub
        if (noScrollViewPager != null) {
            noScrollViewPager.setOffscreenPageLimit(fragments.size());
            setupViewPager(noScrollViewPager, fragments);
        }

    }

    @Override
    public void onSegmentControlClick(int index) {
        // TODO Auto-generated method stub
        noScrollViewPager.setCurrentItem(index, false);
    }


    @Override
    protected void onResume() {
        super.onResume();
        MobclickAgent.onPageStart("RechangeNewActivity");
        MobclickAgent.onResume(this);
    }

    @Override
    protected void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd("RechangeNewActivity");
        MobclickAgent.onPause(this);
    }

}
